#
#  Subject controller
#

from dzutil import message
from views.subject_view import *
from models.subject import Subjects, Subject

#------------------------------------------------------------------------
class SubjectController:

    def _index(self):
		return SubjectListView()

    def _show(self,key):
		return SubjectShowView(key)

    def _edit(self,key):
		return SubjectEditView(key)

    def _confirm_delete(self,key):
		return SubjectDeleteView(key)

    def _delete(self,SUBJECTID,yes_button):
        import dzutil
        subjects = Subjects()
        subject = subjects.seek(SUBJECTID)
        subjects.delete(subject)
        message('Deleted %s' % subject.NAME)
        return SubjectListView()

    def _add(self):
        return SubjectAddView()

    def _update(self,SUBJECTID,**args):
        subjects = Subjects()
        subject = subjects.seek(SUBJECTID)
        subject.update(args)
        subjects.update(subject)
        message('Updated')
        return SubjectShowView(SUBJECTID)

    def _insert(self,**args):
        subjects = Subjects()
        subject = subjects.new()
        subject.update(args)
        newid = subjects.insert(subject)
        message('Added %s' % subject.NAME)
        return SubjectListView()


result = SubjectController()

